from pydantic import BaseModel, Field
from typing import Optional, List
from enum import Enum

class AnimationType(str, Enum):
    """3D模型动画类型枚举"""
    IDLE = "idle"           # 待机
    TALK = "talk"           # 说话
    NOD = "nod"             # 点头
    WAVE = "wave"           # 挥手
    HAPPY = "happy"         # 开心
    THINKING = "thinking"   # 思考
    SURPRISED = "surprised" # 惊讶

class ChatRequest(BaseModel):
    """聊天请求模型"""
    message: str = Field(..., description="用户输入的消息", min_length=1, max_length=1000)
    user_id: Optional[str] = Field(default=None, description="用户ID（可选）")
    session_id: Optional[str] = Field(default=None, description="会话ID（可选）")
    
    class Config:
        json_schema_extra = {
            "example": {
                "message": "你好，我想和你聊天",
                "user_id": "user123",
                "session_id": "session456"
            }
        }

class ChatResponse(BaseModel):
    """聊天响应模型"""
    reply: str = Field(..., description="AI回复的文本")
    audio_url: Optional[str] = Field(default=None, description="语音合成音频文件的URL")
    animation: AnimationType = Field(default=AnimationType.TALK, description="建议的3D模型动画")
    emotion: Optional[str] = Field(default=None, description="检测到的情绪")
    duration: Optional[float] = Field(default=None, description="音频时长（秒）")
    timestamps: Optional[List[dict]] = Field(default=None, description="句子时间戳列表，包含text、start_time、end_time")
    
    class Config:
        json_schema_extra = {
            "example": {
                "reply": "你好！很高兴和你聊天！",
                "audio_url": "/audio/response_123.mp3",
                "animation": "talk",
                "emotion": "happy",
                "duration": 3.5,
                "timestamps": [
                    {"text": "你好！", "start_time": 0.0, "end_time": 1.2},
                    {"text": "很高兴和你聊天！", "start_time": 1.2, "end_time": 3.5}
                ]
            }
        }

class TTSRequest(BaseModel):
    """语音合成请求模型"""
    text: str = Field(..., description="要合成语音的文本", min_length=1, max_length=500)
    voice: Optional[str] = Field(default="zhichu", description="语音类型")
    
class ErrorResponse(BaseModel):
    """错误响应模型"""
    error: str = Field(..., description="错误信息")
    code: Optional[str] = Field(default=None, description="错误代码")
    details: Optional[dict] = Field(default=None, description="错误详情")